import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import pxtovw from "postcss-px-to-viewport";
import path from "path";
const usePxtovw = pxtovw({
  viewportWidth: 375, // 设计稿的视口宽度
  viewportUnit: "vw", // 希望使用的视口单位
  unitPrecision: 5, // 单位转换后保留的精度
});

// https://vite.dev/config/
export default defineConfig({
  plugins: [react()],
  css: {
    postcss: {
      plugins: [usePxtovw],
    },
  },
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  //解决跨域问题
  server: {
    proxy: {
      "/api": {
        target: "http://localhost:8000/",  
        changeOrigin: true,
        rewrite: (path) => path.replace("/api", ""),
      },
      "/v1": {
        target: "http://www.chunyuyisheng.com",
        changeOrigin: true,
        rewrite: (path) => path.replace("/v1", ""),
      },
    },

  },
});
